<?php
$post = $_POST;
$dst = './';
if ($post['index'] == 1) {
    //文件存在删除
    if (file_exists($dst . $post['filename'])) {
        unlink($dst . $post['filename']);
    }
}
$r = file_put_contents($dst . $post['filename'], $post['data'], FILE_APPEND);
if (!$r) {
    echo json_encode([
        'status' => false,
        'msg' => 'fail',
        'filesize' => filesize($dst . $post['filename']),
        'md5' => md5_file($dst . $post['filename']),
        'url' => '',
    ]);
    exit;
}
if ($post['index'] == $post['total']) {
    if (filesize($dst . $post['filename']) != $post['filesize'] || md5_file($dst . $post['filename']) != $post['md5']) {
        echo json_encode([
            'status' => false,
            'msg' => 'fail',
            'filesize' => filesize($dst . $post['filename']),
            'md5' => md5_file($dst . $post['filename']),
            'url' => '',
        ]);
        exit;
    }
    echo json_encode([
        'status' => true,
        'msg' => 'success',
        'filesize' => filesize($dst . $post['filename']),
        'md5' => md5_file($dst . $post['filename']),
        'url' => 'https://www.baidu.com',
    ]);
    exit;
}
echo json_encode([
    'status' => true,
    'msg' => 'uploading',
    'filesize' => filesize($dst . $post['filename']),
    'md5' => md5_file($dst . $post['filename']),
    'url' => '',
]);
exit;


